package com.Ajava1704.for并发包下的类.ForCycliyer;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * 作者: LCG
 * 日期: 2020/2/11 10:54
 * 描述:
 */
public class ForCycliRunable implements Runnable {

    private CyclicBarrier cyclicBarrier;

    private int time;

    public ForCycliRunable(CyclicBarrier cyclicBarrier, int time) {
        this.cyclicBarrier = cyclicBarrier;
        this.time = time;
    }

    @Override
    public void run() {

        try {
            Thread.sleep(time*1000);
            System.out.println(Thread.currentThread().getName()+"运动员就位。。。。。");
            cyclicBarrier.await();//线程阻塞到当前的屏障点
            System.out.println(Thread.currentThread().getName()+"运动员起跑。。。。。");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }

    }
}
